<?php
require_once dirname(__FILE__)."/../init.php";

include "header.php";
include "navigation.php";

?>
<br/>
<fb:fbml version="1.1">
<?php

$success = $_GET['success'];
if ($success != null && $success == "true") {
?>
<fb:success message="Your message has been sent." />
<?php
} else if ($success != null && $success == "false") {
?>
<fb:error message="There was a problem sending your message." />
<?php
}

?>
<fb:editor action="index.php?_action=saveMessage" labelwidth="100">
	<fb:editor-custom label="Recipient">
		<fb:typeahead-input name="recipient" autocomplete="off" label="Phone number" value="">
                    <?php
                    $owner = ServiceFactory::getUserService()->getByUid($_uid);
                    $contactList = ServiceFactory::getContactService()->getContactsByUserId($owner->getId());

                    foreach ($contactList as $contactItem) {
                    ?>
                    <fb:typeahead-option><?php echo $contactItem->getFullName(); ?> (<?php echo $contactItem->getMobileNumber(); ?>)</fb:typeahead-option>
                    <?php } ?>
		</fb:typeahead-input>
	</fb:editor-custom>
	<fb:editor-textarea label="Message" name="message" rows="4"/>
	<fb:editor-custom>Only the first 400 characters of your message will be sent.</fb:editor-custom>
	<fb:editor-divider/>
	<fb:editor-buttonset>
		<fb:editor-button value="Send" name="send"/>
                <fb:editor-button value="Save as Draft" name="draft"/>
	</fb:editor-buttonset>
</fb:editor>
</fb:fbml>